<template>
 <div>
     <ve-line :data="chartData"></ve-line>
 </div>
</template>

<script>
import VeLine from 'v-charts/lib/line.common'
import {getcurrentlight} from '../../api/api'
import { setInterval } from 'timers';
var i = 0;

  export default {
    data(){
        return{
            chartData:{}
        }
    },
    created(){
        this.getData();
    },
    components: { VeLine },
    methods:{
         getData(){
              var that = this;
             setInterval(function(){
                 that.c();
             },5000);
         },
        c(){
            getcurrentlight().then(data=>{
                let arr= [];
                data.forEach((item,index) => {
                    let obj = {};
                    obj.光照 = item.light;
                    obj.时间 = item.light_time;
                    arr.push(obj);
                });
                this.chartData = {
                    columns: ['时间', '光照'],
                    rows: arr
                }; 
             });
        }
    }
  }
</script>

<style lang="scss" scoped>
   
</style>
